package org.afun.csms_android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.csms_android.R;
import org.afun.csms_android.domain.Course;
import org.afun.csms_android.domain.javaBean.SS;

import java.util.List;

public class StudentShowCourseAdapter extends RecyclerView.Adapter<StudentShowCourseAdapter.ViewHolder> {
    private List<SS> mCourseList;
    private Context mContext;

    static class ViewHolder extends RecyclerView.ViewHolder {
        View ShowCourseView;
        ImageView courseImage;
        TextView courseMsg;

        public ViewHolder(View view){
            super(view);
            ShowCourseView=view;
            courseImage=(ImageView) view.findViewById(R.id.showcourse_image);
            courseMsg=view.findViewById(R.id.showcourse_msg);
        }

    }

    public StudentShowCourseAdapter(List<SS> courseList,Context context) {
        this.mCourseList=courseList;
        mContext=context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.student_show_course_item, parent, false);
        final ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        SS ss = mCourseList.get(position);
        holder.courseImage.setImageResource(R.drawable.forumimg);
        int couId = ss.getCouId();
        String couName = ss.getCouName();
        String teaName = ss.getTeaName();
        int credit = ss.getCredit();

        holder.courseMsg.setText(
                "课程号："+couId+"\n课程名："+couName+"\n教师："+teaName+"\n学分："+credit
        );
    }

    @Override
    public int getItemCount() {
        return mCourseList.size();
    }
}
